package top.dancun.easteacher.controller;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.dancun.common.utils.PageUtils;
import top.dancun.common.utils.R;
import top.dancun.easteacher.entity.EvaluationTeachingEntity;
import top.dancun.easteacher.service.EvaluationTeachingService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 评教表
 *
 * @author dancun
 * @email message@dancun.top
 * @date 2022-11-05 10:17:22
 */
@RestController
@RequestMapping("/evaluationteaching")
public class EvaluationTeachingController extends AbstractController{
    @Autowired
    private EvaluationTeachingService evaluationTeachingService;

    /**
     * 获取所有老师的所有学期评教
     */
    @RequestMapping("/list")
    @RequiresPermissions("easstudent:evaluationteaching:list")
    public R list(@RequestBody Map<String, String> params){
        PageUtils page = evaluationTeachingService.getAll(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("easstudent:evaluationteaching:info")
    public R info(@PathVariable("id") Long id){
		EvaluationTeachingEntity evaluationTeaching = evaluationTeachingService.getById(id);

        return R.ok().put("et", evaluationTeaching);
    }
    /**
     * 获取自己对老师的评价（学生用）
     */
    @PostMapping("/getbytidandsid")
    @RequiresPermissions("easstudent:evaluationteaching:getbytidandsid")
    public R getByTidAndSid(@RequestBody Map<String,String > params){
        params.put("studentId",getUserId());

        EvaluationTeachingEntity evaluationTeaching = evaluationTeachingService.getBySTS(params);


        return R.ok().put("et", evaluationTeaching);
    }


    /**
     * 查询教师综合评价，按学期
     * @param params
     * @return R
     */
    @PostMapping("/getbytid")
    @RequiresPermissions("easstudent:evaluationteaching:getbytid")
    public R getByTid(@RequestBody Map<String,String > params){
        params.put("teacherId",getUserId());

        PageUtils page = evaluationTeachingService.getByTid(params);


        return R.ok().put("page", page);
    }
    @PostMapping("gettop")
    @RequiresPermissions("easstudent:evaluationteaching:list")
    public R getTop(){
        return  R.ok().put("data",evaluationTeachingService.getTop().getList());
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("easstudent:evaluationteaching:save")
    public R save(@RequestBody EvaluationTeachingEntity evaluationTeaching){
        evaluationTeaching.setStudentId(getUserId());
		evaluationTeachingService.save(evaluationTeaching);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("easstudent:evaluationteaching:update")
    public R update(@RequestBody EvaluationTeachingEntity evaluationTeaching){
		evaluationTeachingService.updateById(evaluationTeaching);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("easstudent:evaluationteaching:delete")
    public R delete(@RequestBody Long[] ids){
		evaluationTeachingService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
